<%--
  Created by IntelliJ IDEA.
  User: bwj
  Date: 2021/6/22
  Time: 11:18
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <base href="<%=basePath%>">
    <title>
        车次管理
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="css/main.css" media="all">
    <script type="text/javascript" src="lib/loading/okLoading.js"></script>
    <link rel="stylesheet" href="css/bootstrap.css">
    <link rel="stylesheet" href="css/myPagination.css">
    <script type="text/javascript" src="js/myPagination.js" charset="UTF-8"></script>
    <script type="text/javascript" src="js/jquery-3.2.1.js" charset="UTF-8"></script>
    <script type="text/javascript" src="js/admin_region.js" charset="UTF-8"></script>
</head>

<body>
<div class="x-nav">
            <span class="layui-breadcrumb">
              <a><cite>首页</cite></a>
              <a><cite>车次管理</cite></a>
              <a><cite>车次添加</cite></a>
            </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       href="javascript:location.replace(location.href);" title="刷新"><i class="layui-icon"
                                                                        style="line-height:30px">ဂ</i></a>
</div>
<div class="x-body">
    <form class="layui-form x-center" action="" style="width:800px">
        <div class="layui-form-pane" style="margin-top: 15px;">
            <div class="layui-form-item">
                <div class="layui-input-inline">
                    <table>
                        <tr>
                            <td><input type="text" name="lieche" placeholder="路线查询" autocomplete="off"
                                       class="layui-input" style="height: 25px; width: 120px;" id="querytrainid"
                                       value="${trainquery}"></td>
                            <td><input type="button" value="查询" style="height: 25px; width: 50px;"
                                       onclick="querytrainbyid()"/></td>
                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

                        </tr>
                    </table>
                </div>
            </div>
        </div>
    </form>
    <xblock>
        <button class="layui-btn" onclick="tnadd()"><i class="layui-icon">&#xe608;</i>添加路线</button>
        <span class="x-right" style="line-height:40px">共有数据：${trainsCount} 条</span>
    </xblock>
    <table class="layui-table">
        <thead>
        <tr>
            <th>

            </th>
            <th>
                列车名
            </th>
            <th>
                列车类型
            </th>
            <th>
                起始站
            </th>
            <th>
                终点站
            </th>
            <th>
                出发时间
            </th>
            <th>
                里程价格
            </th>
            <th>
                操作
            </th>
        </tr>
        </thead>
        <tbody id="ches">
        <c:forEach items="${trainsList}" var="t" varStatus="index">
            <tr>
                <td>
                        ${index.count}
                </td>
                <td>
                        ${t.trainName}
                </td>
                <td>
                        ${t.trainType.typeName}
                </td>
                <td>
                        ${t.start.siteName}
                </td>

                <td>
                        ${t.destination.siteName}
                </td>
                <td>
                    <fmt:formatDate value="${t.departureTime}" pattern="HH:mm"/>
                </td>
                <td>
                        ${t.mileagePrice}
                </td>

                <td class="td-manage">
                    <a title="添加车次" href="javascript:;"
                       onclick="activity_add('添加车次','train/${t.trainId}/tnadd','600','500')"
                       class="ml-5" style="text-decoration:none">
                        <i class="layui-icon">&#xe642;</i>
                    </a>&nbsp;&nbsp;&nbsp;

                    <!--   <a title="删除列车" href="javascript:;" onclick="activity_del(this,'1')"
                          style="text-decoration:none">
                           <i class="layui-icon">&#xe640;</i>
                       </a>-->
                </td>
            </tr>
        </c:forEach>
        <tr></tr>
        </tbody>

    </table>
    <div class="pagination" id="pagination"></div>

    <div id="page"></div>
</div>
<script>
    window.onload = function () {
        new myPagination({
            id: 'pagination',
            curPage: ${cspage},//初始页码
            pageTotal:${trainPages},//总页数
            pageAmount: 5, //每页多少条
            dataTotal: ${trainsCount},//总共多少条数据
            pageSize: 5,//可选，分页个数
            showPageTotalFlag: true,//是否显示数据统计
            showSkipInputFlag: true, //是否支持跳转
            getPage: function (page1) {
                //分页跳转
                if (${pageFlag=='1'}) {
                    javascript:location.replace("train/" + page1 + "/toAdminRegion");
                } else {
                    javascript:location.replace("train/" + page1 + "/toAdminRegion");
                }
            }
        });
    }
</script>
<script src="lib/layui/layui.js" charset="utf-8"></script>
<script src="js/x-layui.js" charset="utf-8"></script>

<script>

    layui.use(['laydate', 'element', 'laypage', 'layer'], function () {
        $ = layui.jquery;//jquery
        laydate = layui.laydate;//日期插件
        lement = layui.element();//面包导航
        laypage = layui.laypage;//分页
        layer = layui.layer;//弹出层
        okLoading.close($);
        //以上模块根据需要引入


        var start = {
            min: '1999-06-16 23:59:59'
            , max: '2099-06-16 23:59:59'
            , istoday: false
            , choose: function (datas) {
                end.min = datas; //开始日选好后，重置结束日的最小日期
                end.start = datas //将结束日的初始值设定为开始日
            }
        };

        var end = {
            min: laydate.now()
            , max: '2099-06-16 23:59:59'
            , istoday: false
            , choose: function (datas) {
                start.max = datas; //结束日选好后，重置开始日的最大日期
            }
        };

        document.getElementById('LAY_demorange_s').onclick = function () {
            start.elem = this;
            laydate(start);
        }
        document.getElementById('LAY_demorange_e').onclick = function () {
            end.elem = this
            laydate(end);
        }
    });

    //批量删除提交
    function delAll() {
        layer.confirm('确认要删除吗？', function (index) {
            //捉到所有被选中的，发异步进行删除
            layer.msg('删除成功', {icon: 1});
        });
    }

    function question_show(argument) {
        layer.msg('可以跳到前台具体问题页面', {icon: 1, time: 1000});
    }

    /*添加*/
    function activity_add(title, url, w, h) {
        x_admin_show(title, url, w, h);
    }

    //编辑
    function activity_edit(title, url, id, w, h) {
        url = url + "?id=" + id;
        x_admin_show(title, url, w, h);
    }

    /*删除*/
    function activity_del(obj, id) {
        layer.confirm('确认要删除吗？', {icon: 3, title: '提示信息'}, function (index) {
            $.ajax({
                type: "post",
                url: "xxx",
                data: {id: id},
                dataType: "json",
                success: function (data) {
                    //console.log(data);
                    if (data.status == 1) {
                        //发异步删除数据
                        $(obj).parents("tr").remove();
                        layer.msg(data.info, {icon: 6, time: 1000});
                        setTimeout(function () {
                            window.location.reload();
                        }, 1000);
                        return false;
                    } else {
                        layer.msg(data.info, {icon: 5, time: 1000});
                        return false;
                    }
                }
            });
            //发异步删除数据
            $(obj).parents("tr").remove();
            layer.msg('已删除!', {icon: 1, time: 1000});
        });
    }
</script>
</body>
</html>